package com.hhit.bigscreenbackmanage.controller.aqgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.common.Response;
import com.hhit.bigscreenbackmanage.entity.aqgl.TAqglDrrygkTemp;
import com.hhit.bigscreenbackmanage.entity.aqgl.TAqglMrbo;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglDrrygkTempService;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglJdjcqkSblzService;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglJdjcqkYcjcService;
import com.hhit.bigscreenbackmanage.service.aqgl.AqglMrboService;
import com.hhit.bigscreenbackmanage.vo.DeleteVo;
import com.hhit.bigscreenbackmanage.vo.aqgl.AqglSearchVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName AqglTempController
 * @Description
 * @Author qianchengcheng
 * @Date 2021/7/27
 */
@RequestMapping("/aqgl")
@RestController
public class AqglTempController {

    private static Logger log = LoggerFactory.getLogger(AqglTempController.class);

    @Autowired
    private AqglDrrygkTempService aqglDrrygkTempService;

    @Autowired
    private AqglMrboService aqglMrboService;

    @Autowired
    private AqglJdjcqkSblzService aqglJdjcqkSblzService;

    @Autowired
    private AqglJdjcqkYcjcService aqglJdjcqkYcjcService;

    @PostMapping("/saveAqglDrrygkTempInfo")
    public Response saveAqglDrrygkTempInfo(@RequestBody TAqglDrrygkTemp tAqglDrrygkTemp){
        try {
            int addRes = aqglDrrygkTempService.saveAqglDrrygkTempInfo(tAqglDrrygkTemp);
            if (addRes > 0){
                return Response.createResponseBySuccess("添加成功");
            }
            if (addRes == -1){
                return Response.createResponseByError("添加失败,请求对象为空");
            }
            return Response.createResponseByError("添加失败");
        }catch (Exception e){
            log.error("AqglTempController.saveAqglDrrygkTempInfo Call Error",e);
            return Response.createResponseByError("添加异常");
        }
    }

    @PostMapping("/updateAqglDrrygkTempInfo")
    public Response updateAqglDrrygkTempInfo(@RequestBody TAqglDrrygkTemp tAqglDrrygkTemp){
        try {
            int updateRes = aqglDrrygkTempService.updateAqglDrrygkTempInfo(tAqglDrrygkTemp);
            if (updateRes > 0){
                return Response.createResponseBySuccess("更新成功");
            }
            if (updateRes == -1){
                return Response.createResponseByError("更新失败,请求对象为空");
            }
            return Response.createResponseByError("更新失败");
        }catch (Exception e){
            log.error("AqglTempController.updateAqglDrrygkTempInfo Call Error",e);
            return Response.createResponseByError("更新异常");
        }
    }

    @PostMapping("/batchDeleteAqglDrrygkTempInfo")
    public Response batchDeleteAqglDrrygkTempInfo(@RequestBody DeleteVo deleteVo){
        try {
            int deleteRes = aqglDrrygkTempService.batchDeleteAqglDrrygkTempInfo(deleteVo);
            if (deleteRes > 0){
                return Response.createResponseBySuccess("删除成功");
            }
            if (deleteRes == -1){
                return Response.createResponseByError("删除失败,请求对象为空");
            }
            return Response.createResponseByError("删除失败");
        }catch (Exception e){
            log.error("AqglTempController.batchDeleteAqglDrrygkTempInfo Call Error",e);
            return Response.createResponseByError("删除异常");
        }
    }

    @PostMapping("/getAqglDrrygkTempPageInfo")
    public Response getAqglDrrygkTempPageInfo(@RequestBody AqglSearchVo aqglSearchVo){
        try {
            return Response.createResponseBySuccess("查询成功",aqglDrrygkTempService.getAqglDrrygkTempPageInfo(aqglSearchVo));
        }catch (Exception e){
            log.error("AqglTempController.getAqglDrrygkTempPageInfo Call Error",e);
            return Response.createResponseByError("查询异常");
        }
    }


    /**
     * 新增每日播报
     * @param tAqglMrbo
     * @return
     */
    @PostMapping("/saveAqglMrboTempInfo")
    public Response saveAqglMrboInfo(@RequestBody TAqglMrbo tAqglMrbo){
        try {
            int addRes = aqglMrboService.insertAqglMrbo(tAqglMrbo);
            if (addRes > 0){
                return Response.createResponseBySuccess("添加成功");
            }
            if (addRes == -1){
                return Response.createResponseByError("添加失败,请求对象为空");
            }
            return Response.createResponseByError("添加失败");
        }catch (Exception e){
            log.error("aqglMrboService.saveAqglMrboInfo Call Error",e);
            return Response.createResponseByError("添加异常");
        }
    }

    /**
     * 修改每日播报
     * @param tAqglMrbo
     * @return
     */
    @PostMapping("/updateAqglMrboTempInfo")
    public Response updateAqglMrboInfo(@RequestBody TAqglMrbo tAqglMrbo){
        try {
            int addRes = aqglMrboService.updateAqglMrbo(tAqglMrbo);
            if (addRes > 0){
                return Response.createResponseBySuccess("修改成功");
            }
            if (addRes == -1){
                return Response.createResponseByError("修改失败,请求对象为空");
            }
            return Response.createResponseByError("修改失败");
        }catch (Exception e){
            log.error("aqglMrboService.updateAqglMrboInfo Call Error",e);
            return Response.createResponseByError("修改异常");
        }
    }

    /**
     * 删除每日播报
     * @param json
     * @return
     */
    @PostMapping("/deleteAqglMrboTempInfo")
    public Response deleteAqglMrboInfo(@RequestBody JSONObject json){
        try {
            int addRes = aqglMrboService.deleteAqglMrbo(json.get("datetime").toString());
            if (addRes > 0){
                return Response.createResponseBySuccess("删除成功");
            }
            if (addRes == -1){
                return Response.createResponseByError("删除失败,请求对象为空");
            }
            return Response.createResponseByError("删除失败");
        }catch (Exception e){
            log.error("aqglMrboService.deleteAqglMrboInfo Call Error",e);
            return Response.createResponseByError("删除异常");
        }
    }

    @PostMapping("/deleteAqglJdjcqkSblz")
    public Response deleteAqglJdjcqkSblz(@RequestBody JSONObject json){
        try {
            int delRes = aqglJdjcqkSblzService.batchDeleteAqglJdjcqkSblz(json);
            if (delRes > 0){
                return Response.createResponseBySuccess("删除成功",delRes);
            }
            if (delRes == -1){
                return Response.createResponseByError("删除失败,请求对象为空");
            }
            return Response.createResponseByError("删除失败");
        }catch (Exception e){
            log.error("aqglMrboService.deleteAqglJdjcqkSblz Call Error",e);
            return Response.createResponseByError("删除异常");
        }
    }

    @PostMapping("/deleteAqglJdjcqkYcjc")
    public Response deleteAqglJdjcqkYcjc(@RequestBody JSONObject json){
        try {
            int delRes = aqglJdjcqkYcjcService.batchDeleteAqglJdjcqkYcjc(json);
            if (delRes > 0){
                return Response.createResponseBySuccess("删除成功",delRes);
            }
            if (delRes == -1){
                return Response.createResponseByError("删除失败,请求对象为空");
            }
            return Response.createResponseByError("删除失败");
        }catch (Exception e){
            log.error("aqglMrboService.deleteAqglJdjcqkYcjc Call Error",e);
            return Response.createResponseByError("删除异常");
        }
    }
}
